function obtenHoja(optional indiceHoja as integer) as object
dim doc, hoja as object
doc = thiscomponent
if isMissing(indiceHoja) Then
'obtengo hoja actual
hoja = doc.getCurrentController().getActiveSheet()
else
'obtengo hoja dado el indice
hoja = doc.sheets(indiceHoja)
end if
obtenHoja = hoja
end function
function leerNumero(col as integer, fil as integer, optional indiceHoja as integer) as variant
dim hoja as object
hoja = obtenHoja(indiceHoja)
leerNumero = hoja.getCellByPosition(col,fil).value
end function
sub escribeNumero(col as integer, fil as integer, valor as variant, optional indiceHoja)
dim hoja as object
hoja = obtenHoja(indiceHoja)
hoja.getCellByPosition(col,fil).value = valor
end sub
sub escribeTexto(col as integer, fil as integer, texto as string, optional indiceHoja)
dim hoja as object
hoja = obtenHoja(indiceHoja)
hoja.getCellByPosition(col,fil).setstring(texto)
end sub
sub obtenIndicesCelda(byref col, byref fil)
Dim direccionCelda as New com.sun.star.table.CellAddress
direccionCelda = thisComponent.getCurrentSelection().getCellAddress()
col = direccionCelda.column
fil = direccionCelda.row
end sub
'0 exento
'1 superreducido
'2 reducido
'3 general
function pvp(neto as double, optional tipo as integer) as double
dim iva as double
if isMissing(tipo) Then
tipo = 3
end if
'CONDICIONALES SIMPLES NO ANIDADOS
'if tipo=0 then
' iva = 1.0
'end if
'if tipo=1 then
' iva = 1.04
'end if
'if tipo=2 then
' iva = 1.1
'end if
'if tipo=3 then
' iva = 1.21
'end if
'CONDICIONAL SIMPLE ANIDADO
'if tipo = 0 then
' iva = 1.0
'elseif tipo = 1 then
' iva = 1.04
'elseif tipo = 2 then
' iva = 1.10
'else
' iva = 1.21
'end if
'CONDICIONAL COMPUESTO
select case tipo
case 0
iva = 1.0
case 1
iva = 1.04
case 2
iva = 1.10
case else
iva = 1.21
end select
pvp = neto*iva
end function
function neto(pvp as double, optional tipo as integer) as double
dim iva as double
if isMissing(tipo) Then
tipo = 3
end if
select case tipo
case 0
iva = 1.0
case 1
iva = 1.04
case 2
iva = 1.10
case else
iva = 1.21
end select
neto = pvp/iva
end function
Function extraeCodigo(texto as String)
extraeCodigo = left(texto,5)
'msgbox ("Proceso finalizado")
End Function
Function extraeMunicipio(texto as string)
extraeMunicipio = right(texto, len(texto) -8)
End function
function calc(n1 as double, n2 as double, optional op as integer) as variant
dim res as variant
if isMissing(op) Then
op = 0
end if
select case op
case 0
res = n1 + n2
case 1
res = n1 - n2
case 2
res = n1 * n2
case 3
res = n1 / n2
case 4
res = n1 ^ n2
case 5
res = sqr(n2)
case 6
if n1 mod n2 = 0 then
res = "divisible"
else
res = "no divisible"
end if
end select
calc = res
end function
function bucleFor(inicio as integer, final as integer, optional incremento as integer)
dim iterador as integer
if isMissing(incremento) Then
incremento = 1
end if
for iterador = inicio to final step incremento
escribeNumero(iterador, 0, iterador*2, 0)
next
end function
function bucleWhile()
dim numero as integer
numero = 1
while(numero < 11)
escribeNumero(numero, 1, numero*3, 0)
numero = numero + 1
wend
end function
function cuadro(optional capital as double, optional interes as double, optional plazo as integer)
dim cuota as double
if ismissing(interes) or ismissing(interes) or ismissing(plazo) then
msgbox "CUADRO( [capital] ; [interés anual] ; [plazo en años] )" & Chr$(13) & _
"Ejemplo: CUADRO(15000;2;5)", 64,"Ayuda de uso de la función"
exit function
end if
if capital<=0 or interes <=0 or plazo <=0 then
msgbox "No se permiten valores menores o iguales a cero",16,"Información de uso de la función"
exit function
end if
interes = interes/1200
plazo = plazo*12
cuota = (capital*interes)/(1-(1+interes)^-plazo)
'fila 0
dim col, fil as integer
obtenIndicesCelda(col, fil)
'Etiquetas
fil = fil+1
escribeTexto(col,fil,"Num. cuota")
escribeTexto(col+1,fil,"Inter. cuota")
escribeTexto(col+2,fil,"Amort. cuota")
escribeTexto(col+3,fil,"Pendiente")
'Cuota cero
fil = fil+1
escribeNumero(col,fil,0)
escribeTexto(col+1,fil,"- - -")
escribeTexto(col+2,fil,"- - -")
escribeNumero(col+3,fil,capital)
'Cuadro de amortizacion
dim interesCuota, amortizacionCuota, capitalPendiente as double
dim i as integer
capitalPendiente = capital
for i=1 to plazo step 1
'numero de cuota
escribeNumero(col,fil+i,i)
'interes cuota
interesCuota = interes * capitalPendiente
escribeNumero(col+1,fil+i,interesCuota)
'amortizacion cuota
amortizacionCuota = cuota - interesCuota
escribeNumero(col+2,fil+i,amortizacionCuota)
'capital pendiente
capitalPendiente = capitalPendiente - amortizacionCuota
escribeNumero(col+3,fil+i,capitalPendiente)
next
cuadro = cuota
end function